require(['jquery', 'cookie', 'app', "lay"], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: {},
                userInfo: {},
                money: "",
                thatUser: "",
                blance: [],
                deposit: [],
                site: [],
                permance: {}
            }
            , created: function () {
                this.userInfo = JSON.parse(localStorage.getItem("userInfo"));
                this.loadPage();
            }
            , methods: {
                loadPage: function () {
                    load();
                    var toolbar = [];
                    var tool = [];
                    toolbar.push({
                        "clas": "",
                        "eve": "TU",
                        "tit": "查看邀请图谱",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            layui.use(["layer", "admin", 'index'], function () {
                                var b = layui.layer;
                                var $ = layui.jquery, index = layui.index, admin = layui.admin;
                                admin.changeTheme(localStorage.getItem("theme"));
                                // 默认加载主页
                                index.openTab({
                                    title: '查看图谱',
                                    url: '/view/user/tu?userId=' + data[0].id
                                })
                            })
                        }
                    });
                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "XG",
                        "tit": "重置密码",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            loading();
                            var re = playGet("/v1/api/user/password/reload/" + data[0]["id"], "", "");
                            reloading();
                            alr(re["msg"]);
                            setTimeout(function () {
                                window.location.reload();
                            }, 1000);
                        }
                    });
                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "SPPPP",
                        "tit": "删除用户（谨慎操作）",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            loading();
                            var re = playDelete("/v1/api/user/" + data[0]["id"], "", "");
                            reloading();
                            alr(re["msg"]);
                            setTimeout(function () {
                                window.location.reload();
                            }, 1000);
                        }
                    });
                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "DELXGHHH",
                        "tit": "充值/扣减",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            dic.thatUser = data[0];
                            dic.openAdd();
                        }
                    });
                    /*toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "DELXGHHssssH",
                        "tit": "修改业绩",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            dic.thatUser = data[0];
                            dic.openAdd2();
                        }
                    });*/
                    toolbar.push({
                        "clas": "",
                        "eve": "DELXGHasdadasHssssH",
                        "tit": "查看团队业绩",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            dic.permance = playGet("/v1/api/user/performance/" + data[0]['id'], "", "").data;
                            dic.openAdd3();
                        }
                    });
                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "xoooxoxox",
                        "tit": "修改",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            layui.use(["layer", "admin", 'index'], function () {
                                var b = layui.layer;
                                var $ = layui.jquery, index = layui.index, admin = layui.admin;
                                admin.changeTheme(localStorage.getItem("theme"));
                                // 默认加载主页
                                index.openTab({
                                    title: '修改用户',
                                    url: '/view/user/up?id=' + data[0].id
                                })
                            })
                        }
                    });
                    toolbar.push({
                        "clas": "",
                        "eve": "DELXX",
                        "tit": "查询钱包",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            dic.blance = playGet("v1/api/user/blance/" + data[0]['id'], "", "").data;
                            alrYN($("#admins1"), function () {

                            }, function () {

                            }, function () {

                            }, "查看钱包", 1, ["600px", "350px"]);
                        }
                    });
                    toolbar.push({
                        "clas": "",
                        "eve": "DELXXXX",
                        "tit": "查询提现方式",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            dic.deposit = playGet("v1/api/user/deposit/" + data[0]['id'], "", "").data;
                            alrYN($("#admins4"), function () {

                            }, function () {

                            }, function () {

                            }, "查询提现方式", 1, ["600px", "350px"]);
                        }
                    });
                    toolbar.push({
                        "clas": "",
                        "eve": "DELXXFFF",
                        "tit": "查询收货地址",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            dic.site = playGet("v1/api/user/site/" + data[0]['id'], "", "").data;
                            alrYN($("#admins5"), function () {

                            }, function () {

                            }, function () {

                            }, "查询收货地址", 1, ["600px", "350px"]);
                        }
                    });
                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "DEL",
                        "tit": "禁用/启用",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            loading();
                            var re = playGet("/v1/api/user/status/reload/" + data[0]["id"], "", "");
                            reloading();
                            alr(re["msg"]);
                            setTimeout(function () {
                                window.location.reload();
                            }, 1000);
                        }
                    });
                    toolbar.push({
                        "clas": "layui-btn-danger",
                        "eve": "DELxx123xx",
                        "tit": "激活/冻结",
                        "fnc": function (data) {
                            if (data.length <= 0) {
                                alr("请选择一条记录");
                                return;
                            }
                            loading();
                            var re = playPut("/v1/api/user/userActive/" + data[0]["id"], "", "");
                            reloading();
                            alr(re["msg"]);
                            setTimeout(function () {
                                window.location.reload();
                            }, 1000);
                        }
                    });
                    bspVIEW($("#authoritiesTable"), "/v1/api/user/all", [
                        {type: 'radio',width: 150},
                        {type: 'numbers'},
                        {field: 'id', title: '用户id', minWidth: 50, width: 100},
                        {field: 'name', title: '用户名称', minWidth: 50, width: 100},
                        {field: 'parentName', title: '邀请人', minWidth: 50, width: 100},
                        {field: 'userName', title: '登录账号', minWidth: 50, width: 100},
                        {field: 'mobile', title: '手机', minWidth: 50, width: 100},
                        {
                            templet: function (d) {
                                for (var i = 0; i < d.userBlances.length; i++) {
                                    debugger
                                    if (d.userBlances[i].type.display == 'RMB') {
                                        return d.userBlances[i].money
                                    }
                                }
                            },
                            align: 'center',
                            width: 100,
                            title: '余额'
                            , minWidth: 50
                        },
                        {
                            templet: function (d) {
                                for (var i = 0; i < d.userBlances.length; i++) {
                                    debugger
                                    if (d.userBlances[i].type.display == 'RMB') {
                                        return d.userBlances[i].frostMoney
                                    }
                                }
                            },
                            align: 'center',
                            width: 100,
                            title: '冻结金额'
                            , minWidth: 50
                        },
                        {
                            templet: function (d) {
                                for (var i = 0; i < d.userBlances.length; i++) {
                                    debugger
                                    if (d.userBlances[i].type.display == '积分') {
                                        return d.userBlances[i].money
                                    }
                                }
                            },
                            align: 'center',
                            width: 100,
                            title: '积分'
                            , minWidth: 50
                        },
                        {field: 'inviteNum', title: '邀请人数', minWidth: 50, width: 100},
                        {field: 'selfPerformance', title: '个人业绩', minWidth: 50, width: 100},
                        {
                            templet: function (d) {
                               return d.performance - d.selfPerformance
                            },
                            align: 'center',
                            width: 100,
                            title: '团队业绩'
                            , minWidth: 50
                        },
                        {
                            templet: function (d) {
                                if (d.active) {
                                    return "<p style=\"background-color: green;color: white\">激活 </p>";
                                } else {
                                    return "<p style=\"background-color: red;color: white\">未激活</p>";
                                }
                            },
                            align: 'center',
                            width: 100,
                            title: '团队业绩'
                            , minWidth: 50
                        },
                        {field: 'createTime', title: '注册时间', minWidth: 50, width: 100},
                        {
                            templet: function (d) {
                                if (d.status) {
                                    return "<p style=\"background-color: green;color: white\">启用 </p>";
                                } else {
                                    return "<p style=\"background-color: red;color: white\">禁用</p>";
                                }
                            },
                            align: 'center',
                            width: 100,
                            title: '账号状态'
                            , minWidth: 50
                        },
                        {
                            templet: function (d) {
                                return d.grade.display;
                            },
                            align: 'center',
                            width: 100,
                            title: '会员等级'
                            , minWidth: 120
                        },
                    ], {common: this.where}, toolbar, tool, function (res, curr, count) {

                    });
                },
                seachs: function () {
                    this.where = fromName($(".el-form"));
                    this.loadPage();
                },
                refer: function () {

                },
                openAdd: function () {
                    alrYN($("#admins"), function () {
                        var money = dic.money;
                        var user = dic.thatUser;
                        loading();
                        var MT = $("#admins .layui-form-radioed").prev().val();
                        if (money == 0) {
                            alr("金额不能等于0！");
                            return false;
                        }
                        var re = playPut("v1/api/user/blance/" + user["id"], {
                            "type": MT,
                            "money": money
                        }, "");
                        reloading();
                        alr(re["msg"]);
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                    }, function () {

                    }, function () {

                    }, "请输入金额", 1, ["600px", "350px"]);
                },
                openAdd2: function () {
                    alrYN($("#adminsyj"), function () {
                        var money = dic.money;
                        var user = dic.thatUser;
                        loading();
                        var MT = $("#admins .layui-form-radioed").prev().val();
                        if (money < 0) {
                            alr("不小于0！");
                            return false;
                        }
                        var re = playPut("v1/api/user/userPermance/" + user["id"], {
                            "permance": money
                        }, "");
                        reloading();
                        alr(re["msg"]);
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                    }, function () {

                    }, function () {

                    }, "请输入金额", 1, ["600px", "350px"]);
                },
                openAdd3: function () {
                    alrYN($("#admins3"), function () {

                    }, function () {

                    }, function () {

                    }, "查看总业绩", 1, ["600px", "350px"]);
                }
            }
        });
    })
});